package edu.yctc.manage.utils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author zyj
 * @Description 分页查询工具类
 * @Date 0:45 2021/3/30
 * @Param
 * @return
 **/

public class PageQuery extends LinkedHashMap<String, Object> {

    private static final long serialVersionUID = 1L;
    // 当前页码
    private int page;
    // 每页条数
    private int limit;

    public PageQuery(Map<String, Object> params) {
        this.putAll(params);

        // 分页参数
        this.page = Integer.parseInt(params.get("page").toString());
        this.limit = Integer.parseInt(params.get("limit").toString());
        this.put("start", (page - 1) * limit);
        this.put("page", page);
        this.put("limit", limit);
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("PageQueryUtil [page=");
        builder.append(page);
        builder.append(", limit=");
        builder.append(limit);
        builder.append("]");
        return builder.toString();
    }

}
